package com.hopu.mcshipin.exception;

import com.hopu.mcshipin.entity.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public R handleBusinessException(BusinessException e) {
        return R.err(e.getErrorCode().getCode(), e.getErrorCode().getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        return R.err(500, "服务器异常: " + e.getMessage(), null);
    }
}